package com.abhinav.spring.dao;

import java.util.List;

import javax.persistence.Query;

import org.springframework.stereotype.Component;

import com.abhinav.spring.bean.User;

@Component("userDao")
public class UserDaoImpl extends GenericDaoImpl<User> implements UserDAO {

	/*UserDaoImpl() {
		super();
		setEm(em);
	}*/

	@Override
	public User loadUserByUsername(String username) {
		Query query = this.em.createQuery("SELECT u FROM User u WHERE u.username = :username");
		query.setParameter("username", username);

		List<User> users = query.getResultList();

		if (users != null && users.size() == 1) {
			return users.get(0);
		}

		return null;
	}

}
